﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WEBDT.Base;
using WEBDT.ViewModel;
namespace WEBDT.Areas.Admin.Controllers
{
    public class AccountController : BaseController<Account>
    {
        //
        // GET: /Admin/Account/

        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public  ActionResult updateuser(string id)
        {
            var model = repository.SelectByID1<Account>(id);
            var ht  = new AccountModel
            {
                Username = model.Username,
                Password = model.Password,
                Status = model.Status,
            };
            return View(ht);
        }

        [HttpPost]
        public ActionResult updateuser(FormCollection fr)
        {
            var httt = new AccountModel
            {
                Username = fr.Get("username"),
                Password = fr.Get("password"),
                confirmPass = fr.Get("confirm"),
                Status = Convert.ToInt32(fr.Get("status"))
            };

            if(httt.Password!= httt.confirmPass)
                return View(httt);

            var model = repository.SelectByID1<Account>(httt.Username);
            model.Password = httt.Password;
            model.Status = httt.Status;
            repository.commitchanges();
            return RedirectToAction("getAll");
        }
        [HttpGet]
        public ActionResult Details(string id)
        {
            var model = repository.SelectByID1<UserInfo>(id);
            var ht = new userInfoModel
            {
                UserName = model.Username,
                Ten = model.Ten,
                DiaChi = model.DiaChi,
                DienThoai = model.DienThoai,
                cmnd = model.Cmmd,
                GioiTinh = model.GioiTinh,
                NgaySinh = model.NgaySinh,
            };
            return View(ht);
        }
        [HttpPost]
        public ActionResult Details(FormCollection fr)
        {
            var ht = new userInfoModel
            {
                UserName = fr.Get("username"),
                Ten = fr.Get("ten"),
                DiaChi = fr.Get("diachi"),
                Email = fr.Get("email"),
                DienThoai = fr.Get("dienthoai"),
                cmnd = fr.Get("cmnd"),
                GioiTinh = Convert.ToInt32(fr.Get("gioitinh")),
                NgaySinh = fr.Get("ngaysinh"),
            };

            var model = repository.SelectByID1<UserInfo>(ht.UserName);
            model.Ten = ht.Ten;
            model.DiaChi = ht.DiaChi;
            model.Email = ht.Email;
            model.DienThoai = ht.DienThoai;
            model.Cmmd = ht.cmnd;
            model.GioiTinh = ht.GioiTinh;
            model.NgaySinh = ht.NgaySinh;
            repository.commitchanges();
            return  RedirectToAction("getAll");;
        }
    }
}
